package com.example.demo.service.impl;

import com.example.demo.dao.RotationChartDao;
import com.example.demo.pojo.RotationChart;
import com.example.demo.service.RotationChartService;
import com.example.demo.util.FileUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.ClassUtils;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.util.List;

@Service("rotationChartService")
public class RotationChartServiceImpl implements RotationChartService {
    @Resource
    private RotationChartDao rotationChartDao;
    @Override
    public int deleteByPrimaryKey(Integer pictureid) {
        return rotationChartDao.deleteByPrimaryKey(pictureid);
    }

    @Override
    public int insert(RotationChart record) {
        return rotationChartDao.insert(record);
    }

    @Override
    public int insertSelective(RotationChart record) {
        return rotationChartDao.insertSelective(record);
    }

    @Override
    public RotationChart selectByPrimaryKey(Integer pictureid) {
        return rotationChartDao.selectByPrimaryKey(pictureid);
    }

    @Override
    public int updateByPrimaryKeySelective(RotationChart record) {
        return rotationChartDao.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(RotationChart record) {
        return rotationChartDao.updateByPrimaryKey(record);
    }


    String path=null;
    @Override
    public String Upload(@RequestParam("file") MultipartFile file ){
//        if(!file.isEmpty()){
//            String fileName = file.getOriginalFilename();
//            path="C:\\Users\\lenovo\\Desktop";
//
//            System.out.println("存放图片文件的路径:"+path);
//            try {
//                FileUtil.fileupload(file.getBytes(), path, fileName);
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//            RotationChart chart = new RotationChart();
//            chart.setPictureurl("http://localhost:8081/"+path);
//            rotationChartDao.insert(chart);
//        }
//        return "success";
                return rotationChartDao.Upload(file);
    }

    @Override
    public List<RotationChart> getAll() {
        return rotationChartDao.getAll();
    }
}
